package com.wei.czz.common.dto.annex;

import com.wei.czz.common.tool.BaseEntity;
import com.wei.czz.framework.annex.entity.AnnexGroupEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.TreeSet;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-01-19 14:54:59
 * className: AnnexGroupDto
 * version: 1.0
 * description:
 */
@Getter
@Setter
@Accessors(chain = true)
public class AnnexGroupDto extends BaseEntity implements Comparable<AnnexGroupDto> {

    /**
     * 主键
     */
    private String id;

    /**
     * 父级主键
     */
    private String parentId;

    /**
     * 前置主键
     */
    private String preId;

    /**
     * 名称
     */
    private String name;

    /**
     * 排序等级
     */
    private Integer sort;

    /**
     * 子集合
     */
    private TreeSet<AnnexGroupDto> children;

    @Override
    public int compareTo(AnnexGroupDto o) {
        return sort.compareTo(o.sort);
    }

    /**
     * 附件动态配置分组映射
     * @param annexGroup 附件动态配置分组对象
     * @return 映射结果
     */
    public static AnnexGroupDto map(AnnexGroupEntity annexGroup) {
        AnnexGroupDto annexGroupDto = new AnnexGroupDto();
        annexGroupDto.id = annexGroup.getId().toString();
        annexGroupDto.parentId = annexGroup.getParentId().toString();
        annexGroupDto.preId = annexGroup.getPreId().toString();
        annexGroupDto.name = annexGroup.getName();
        annexGroupDto.sort = annexGroup.getSort();
        return annexGroupDto;
    }

}
